package li.controller;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletResponse;

import li.entity.Book;
import li.service.SearchService;
import li.util.JSONUtil;

import org.json.JSONArray;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller public class SearchController {

	@Autowired
	private SearchService searchService;

	@RequestMapping("/bookQuery/bookname")
	public String bookQueryBookname(String keyword, Model m){
		List<Book> books = searchService.bookQueryBookname(keyword);
		m.addAttribute("books", books);
		return "bookQuery";
	}

	@RequestMapping("/bookQuery/authorname")
	public String bookQueryAuthorname(String keyword, Model m) {
		List<Book> books = searchService.bookQueryAuthorname(keyword);
		m.addAttribute("books", books);
		return "bookQuery";
	}

	@RequestMapping("/bookQuery/bookindex")
	public String bookQueryBookindex(String keyword, Model m){
		List<Book> books = searchService.bookQueryBookindex(keyword);
		m.addAttribute("books", books);
		return "bookQuery";
	}
}
